******************************************************************************************
*Do file to replicate tables and figures in article
******************************************************************************************
*FIGURE 1
*use "votesreceipts.dta", clear

*Label variables
lab var pripctvote "Percent Primary Vote"
lab var pripctreceipts "Percent Primary Receipts"
lab var priuo "Primary Unopposed"
lab var incum "Incumbent"

binsreg pripctvote pripctreceipts, dots(0,0) line(3,3) cb(3,3) polyreg(3) bycolors(gs5) ///
	xtitle("Primary Receipt Share", size(large)) xlabel(0(.2)1, labsize(medium)) graphregion(color(white)) legend(off) title("All Candidates", color(black) size(vlarge)) ///
	ytitle("Primary Vote Share", size(large)) yscale(range(0 1.01)) ylabel(0(.2)1, labsize(medium) angle(0)) yscale(titlegap(2)) xscale(titlegap(2)) 

binsreg pripctvote pripctreceipts if priuo==0, dots(0,0) line(3,3)  cb(3,3) polyreg(3) bycolors(gs5)  ///
	xtitle("Primary Receipt Share", size(large)) xlabel(0(.2)1, labsize(medium)) graphregion(color(white)) legend(off) title("Opposed Candidates", color(black) size(vlarge)) ///
	ytitle("Primary Vote Share", size(large)) yscale(range(0 1.01)) ylabel(0(.2)1, labsize(medium) angle(0)) yscale(titlegap(2)) xscale(titlegap(2)) 

******************************************************************************************
*FIGURE 2
*use "votemoneydata_primary.dta", clear

collapse (mean) competitiveprivotes_575 competitiveprireceipts_575 npricands effectivecands, by(challengerparty incumcontested openseat year)

gen competitiveprivotes_575_pct=competitiveprivotes_575*100
gen competitiveprireceipts_575_pct = competitiveprireceipts_575*100

graph twoway (line competitiveprivotes_575_pct year if openseat==1, lcolor(black) lwidth(medthick)) || ///
	(line competitiveprivotes_575_pct year if challengerparty==1, lcolor(gs7) lwidth(medthick)) || ///
	(line competitiveprivotes_575_pct year if incumcontested==1, lcolor(gs12) lwidth(medthick)),  ///
	yscale(range(-4 102)) ylabel(0(20)100, labsize(medium) angle(0)) ///
	ytitle("Percent of Primaries", size(large)) yscale(titlegap(0)) ///
	title("(a)  57.5% of Votes", color(black) size(vlarge) bexpand nospan) ///
	xscale(range(1979.5 2020.5)) xlabel(1980(4)2020, labsize(medium)) xtitle("") graphregion(color(white)) legend(off) /// 
	text(60 2009  "Open-Seat", size(medlarge) place(n)) text(24 1997.5 "Challenger", size(medlarge) place(n)) ///
	text(-2 2012 "Incumbent", size(medlarge) place(n))

graph twoway (line competitiveprireceipts_575_pct year if openseat==1, lcolor(black) lwidth(medthick)) || ///
	(line competitiveprireceipts_575_pct year if challengerparty==1, lcolor(gs7) lwidth(medthick)) || ///
	(line competitiveprireceipts_575_pct year if incumcontested==1, lcolor(gs12) lwidth(medthick)), ///
	yscale(range(-4 102)) ylabel(0(20)100, labsize(medium) angle(0)) ///
	ytitle("Percent of Primaries", size(large)) yscale(titlegap(0)) ///
	title("(b)  57.5% of Receipts", color(black) size(vlarge) bexpand nospan) ///
	xscale(range(1979.5 2020.5)) xlabel(1980(4)2020, labsize(medium)) xtitle("") graphregion(color(white)) legend(off) /// 
	text(49 2011  "Open-Seat", size(medlarge) place(n)) text(13 1995 "Challenger", size(medlarge) place(n)) ///
	text(-4.3 2012 "Incumbent", size(medlarge) place(n))

graph twoway (line npricands year if openseat==1, lcolor(black) lwidth(medthick)) || ///
	(line npricands year if challengerparty==1, lcolor(gs7) lwidth(medthick)) || ///
	(line npricands year if incumcontested==1, lcolor(gs12) lwidth(medthick)) || ///
	(pcarrowi .8 2015 1.3 2015, lcolor(black) mcolor(black)) || ///
	(pcarrowi 1.92 2002 1.42 2002, lcolor(black) mcolor(black)),  ///
	yscale(range(0 6.1)) ylabel(0(1)6, labsize(medium) angle(0)) ///
	ytitle("Number of Candidates", size(large)) yscale(titlegap(2.5)) ///
	title("(c)  Total Candidates ", color(black) size(vlarge) bexpand nospan) ///
	xscale(range(1979.5 2020.5)) xlabel(1980(4)2020, labsize(medium)) xtitle("") graphregion(color(white)) legend(off) /// 
	text(4.05 2006.7  "Open-Seat", size(medlarge) place(n)) text(.45 2015 "Challenger", size(medlarge) place(n)) ///
	text(2 2002 "Incumbent", size(medlarge) place(n))

graph twoway (line effectivecands year if openseat==1, lcolor(black) lwidth(medthick)) || ///
	(line effectivecands year if challengerparty==1, lcolor(gs7) lwidth(medthick)) || ///
	(line effectivecands year if incumcontested==1, lcolor(gs12) lwidth(medthick)) || ///
	(pcarrowi .34 2002.5 .84 2002.5, lcolor(black) mcolor(black)) || ///
	(pcarrowi 1.65 1987 1.15 1987, lcolor(black) mcolor(black)),  ///
	yscale(range(0 6.1)) ylabel(0(1)6, labsize(medium) angle(0)) ///
	ytitle("Number of Candidates", size(large)) yscale(titlegap(2.5)) ///
	title("(d)  Effective Candidates ", color(black) size(vlarge) bexpand nospan) ///
	xscale(range(1979.5 2020.5)) xlabel(1980(4)2020, labsize(medium)) xtitle("") graphregion(color(white)) legend(off) /// 
	text(2.5 2011  "Open-Seat", size(medlarge) place(n)) text(.27 2006.6 "Challenger", size(medlarge) place(n)) ///
	text(1.45 1990.9 "Incumbent", size(medlarge) place(n))

******************************************************************************************
*TABLE 1, TABLE 2, FIGURE 3, TABLE 3, FIGURE 4
*use "votemoneydata_primary.dta", clear

*TABLE 1
qui reg competitiveprivotes_575 i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo t1_1
qui reg competitiveprireceipts_575 i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo t1_2
qui reg competitiveprivotes_toptwo20 i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo t1_3
qui reg competitiveprireceipts_toptwo20 i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo t1_4

esttab t1_1 t1_2 t1_3 t1_4, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) stats(N r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) 

*TABLE 2
qui reg npricands i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr) 
eststo t2_1
qui reg effectivecands_votes i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr) 
eststo t2_2
qui reg effectivecands i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr) 
eststo t2_3

esttab t2_1 t2_2 t2_3, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) stats(N r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) 

*FIGURE 3
qui ologit diff_votereceipts i.partybalance##i.seattype i.stcd i.year, cluster(stcdyr)
margins, predict(outcome(1)) at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black))  ///
	yscale(range(0 .25)) ylabel(0(.05).25, labsize(medium) angle(0)) ytitle("P(Competitive)," "Votes Not Receipts", size(large)) ///
	yscale(titlegap(2.5)) title("(a)  57.5% of Votes vs. Receipts", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.75 3.2)) xlabel(1 "    Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.095 1.5  "Challenger", size(medlarge) place(n)) text(.033 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.2 1.98 "Open-Seat", size(medlarge) place(n)) ///
	graphregion(color(white)) legend(off) 

qui ologit diff_toptwovotereceipts i.partybalance##i.seattype i.stcd i.year, cluster(stcdyr)
margins, predict(outcome(1)) at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 .25)) ylabel(0(.05).25, labsize(medium) angle(0)) ytitle("P(Competitive)," "Votes Not Receipts", size(large)) ///
	yscale(titlegap(2.5)) title("(b)  20-Pt Vote vs. Receipt Margin", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.75 3.2)) xlabel(1 "    Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.092 1.5  "Challenger", size(medlarge) place(n)) text(.035 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.2 1.98 "Open-Seat", size(medlarge) place(n)) ///
	graphregion(color(white)) legend(off)

qui reg diff_effective i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr)
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med))  ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 2.5)) ylabel(0(.5)2.5, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Receipts)", size(large)) ///
	yscale(titlegap(2.5)) title("(c)  Total vs. Effective (Receipts)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.75 3.2)) xlabel(1 "    Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.21 1.5  "Challenger", size(medlarge) place(n)) text(.265 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(1.74 1.98 "Open-Seat", size(medlarge) place(n)) ///
	graphregion(color(white)) legend(off)
	
qui reg diff_effectivevotes i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr)
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 2.5)) ylabel(0(.5)2.5, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Receipts)", size(large)) ///
	yscale(titlegap(2.5)) title("(d)  Effective (Votes vs. Receipts)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.75 3.2)) xlabel(1 "    Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.03 1.5  "Challenger", size(medlarge) place(n)) text(-.02 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.51 1.98 "Open-Seat", size(medlarge) place(n)) ///
	graphregion(color(white)) legend(off)

*TABLE 3  
replace totalunder10pct=5 if totalunder10pct>5 & totalunder10pct!=.

qui ologit diff_votereceipts i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr) 
eststo t3_1
qui ologit diff_toptwovotereceipts i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr) 
eststo t3_2
qui reg diff_effective i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr) 
eststo t3_3
qui reg diff_effectivevotes i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr) 
eststo t3_4

esttab t3_1 t3_2 t3_3 t3_4, keep(1.totalunder10pct 2.totalunder10pct 3.totalunder10pct 4.totalunder10pct 5.totalunder10pct ///
	1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) stats(N r2_p r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.totalunder10pct 2.totalunder10pct 3.totalunder10pct 4.totalunder10pct 5.totalunder10pct ///
	1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) 

*FIGURE 4
qui ologit diff_votereceipts i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)  
margins, predict(outcome(1)) at(totalunder10pct=(0(1)5) openseat=1 challengerparty=0 partybalance=3)
marginsplot, recast(scatter) plot1opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(black)) yscale(range(-.02 .4)) ylabel(0(.1).4, labsize(medium) angle(0)) ytitle("P(Competitive)," "Votes Not Receipts", size(large)) ///
	yscale(titlegap(2.5)) title("(a)  57.5% of Votes vs. Receipts", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xscale(range(-.3 5.3)) xlabel(0 "0" 1 "1" 2 "2" 3 "3" 4 "4" 5 "5 +", labsize(medium) angle(0)) xtitle("Number of Long-Shot Candidates", size(large)) ///
	xscale(titlegap(2.5)) graphregion(color(white)) legend(off)
	
qui ologit diff_toptwovotereceipts i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)  
margins, predict(outcome(1)) at(totalunder10pct=(0(1)5) openseat=1 challengerparty=0 partybalance=3)
marginsplot, recast(scatter) plot1opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(black)) yscale(range(-.02 .4)) ylabel(0(.1).4, labsize(medium) angle(0)) ytitle("P(Competitive)," "Votes Not Receipts", size(large)) ///
	yscale(titlegap(2.5)) title("(b)  20-Pt Vote vs. Receipt Margin", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xscale(range(-.3 5.3)) xlabel(0 "0" 1 "1" 2 "2" 3 "3" 4 "4" 5 "5 +", labsize(medium) angle(0)) xtitle("Number of Long-Shot Candidates", size(large)) ///
	xscale(titlegap(2.5)) graphregion(color(white)) legend(off)
	
qui reg diff_effective i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)  
margins, at(totalunder10pct=(0(1)5) openseat=1 challengerparty=0 partybalance=3)
marginsplot, recast(scatter) plot1opts(lcolor(gs3) mcolor(black) lwidth(med) msize(vsmall) bfcolor(gs12) blcolor(gs12)) ///
	ci1opts(color(gs3)) yscale(range(-.5 6.2)) ylabel(0(2)6, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Receipts)", size(large)) ///
	yscale(titlegap(2.5)) title("(c)  Total vs. Effective (Receipts)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xscale(range(-.3 5.3)) xlabel(0 "0" 1 "1" 2 "2" 3 "3" 4 "4" 5 "5 +", labsize(medium) angle(0)) xtitle("Number of Long-Shot Candidates", size(large)) ///
	xscale(titlegap(2.5)) graphregion(color(white)) legend(off)

qui reg diff_effectivevotes i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)   
margins, at(totalunder10pct=(0(1)5) openseat=1 challengerparty=0 partybalance=3)
marginsplot, recast(scatter) plot1opts(lcolor(gs3) mcolor(black) lwidth(med) msize(vsmall) bfcolor(gs12) blcolor(gs12)) ///
	ci1opts(color(gs3)) yscale(range(-.5 6.2)) ylabel(0(2)6, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Receipts)", size(large)) ///
	yscale(titlegap(2.5)) title("(d)  Effective (Votes vs. Receipts)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xscale(range(-.3 5.3)) xlabel(0 "0" 1 "1" 2 "2" 3 "3" 4 "4" 5 "5 +", labsize(medium) angle(0)) xtitle("Number of Long-Shot Candidates", size(large)) ///
	xscale(titlegap(2.5)) graphregion(color(white)) legend(off)
	
******************************************************************************************
*APPENDIX
******************************************************************************************
*TABLE A1, FIGURE A1, FIGURE A2
*use "votemoneydata_primary.dta", clear

*TABLE A1
tab competitiveprivotes_575 competitiveprireceipts_575

tab competitiveprivotes_toptwo20 competitiveprireceipts_toptwo20

tab competitiveprivotes_575 competitiveprireceipts_575 if priuo==0

tab competitiveprivotes_toptwo20 competitiveprireceipts_toptwo20 if priuo==0

*FIGURE A1
histogram npricands if npricands<8, freq bin(40)  ///
	bcolor(gs12) xtitle("Total On-Ballot Candidates", size(medium)) ///
	yscale(titlegap(2)) yscale(range(0 12000)) ylabel(0(2000)12000, labsize(medsmall) angle(0)) ylabel(,format(%6.0fc)) ///
	xscale(range(0 7)) xlabel(0(1)7, labsize(medsmall)) ytitle("Number of Primaries" "", size(medlarge)) xscale(titlegap(2.5))  ///
	graphregion(color(white)) legend(off)
 
histogram effectivecands_votes if npricands<8, freq bin(40)  ///
	bcolor(gs12) xtitle("Effective Number of Candidates (Votes)", size(medium)) ///
	yscale(titlegap(2)) yscale(range(0 12000)) ylabel(0(2000)12000, labsize(medsmall) angle(0)) ylabel(,format(%6.0fc)) ///
	xscale(range(0 7)) xlabel(0(1)7, labsize(medsmall)) ytitle("Number of Primaries" "", size(medlarge)) xscale(titlegap(2.5))  ///
	graphregion(color(white)) legend(off)

histogram effectivecands if npricands<8, freq bin(40)  ///
	bcolor(gs12) xtitle("Effective Number of Candidates (Receipts)", size(medium)) ///
	yscale(titlegap(2)) yscale(range(0 12000)) ylabel(0(2000)12000, labsize(medsmall) angle(0)) ylabel(,format(%6.0fc)) ///
	xscale(range(0 7)) xlabel(0(1)7, labsize(medsmall)) ytitle("Number of Primaries", size(medlarge)) xscale(titlegap(2.5))  ///
	graphregion(color(white)) legend(off)

*FIGURE A2
histogram diff_effective if diff_effective<12, freq bin(40)  ///
	bcolor(gs12) xtitle("Difference between Total and Effective Candidates" "(Total — Effective Receipts)", size(medium)) ///
	yscale(titlegap(2)) yscale(range(0 10000)) ylabel(0(2000)10000, labsize(medsmall) angle(0)) ylabel(,format(%6.0fc)) ///
	xscale(range(-3 12)) xlabel(-2(2)12, labsize(medsmall)) ytitle("Number of Primaries" "", size(medlarge)) xscale(titlegap(2.5))  ///
	graphregion(color(white)) legend(off)
 
histogram diff_effective if diff_effective<12 & priuo==0, freq bin(40)  ///
	bcolor(gs12) xtitle("Difference between Total and Effective Candidates" "(Total — Effective Receipts)", size(medium)) ///
	yscale(titlegap(2)) yscale(range(0 2500)) ylabel(0(500)2500, labsize(medsmall) angle(0)) ylabel(,format(%6.0fc)) ///
	xscale(range(-3 12)) xlabel(-2(2)12, labsize(medsmall)) ytitle("Number of Primaries" "(Opposed Races)", size(medlarge)) xscale(titlegap(2.5))  ///
	graphregion(color(white)) legend(off)

histogram diff_effectivevotes if diff_effective<12, freq bin(40)  ///
	bcolor(gs12) xtitle("Difference between Effective Candidates" "(Effective Votes — Effective Receipts)", size(medium)) ///
	yscale(titlegap(2)) yscale(range(0 10000)) ylabel(0(2000)10000, labsize(medsmall) angle(0)) ylabel(,format(%6.0fc)) ///
	xscale(range(-3 12)) xlabel(-2(2)12, labsize(medsmall)) ytitle("Number of Primaries" "", size(medlarge)) xscale(titlegap(2.5))  ///
	graphregion(color(white)) legend(off)

histogram diff_effectivevotes if diff_effective<12 & priuo==0, freq bin(40)  ///
	bcolor(gs12) xtitle("Difference between Effective Candidates" "(Effective Votes — Effective Receipts)", size(medium)) ///
	yscale(titlegap(2)) yscale(range(0 2500)) ylabel(0(500)2500, labsize(medsmall) angle(0)) ylabel(,format(%6.0fc)) ///
	xscale(range(-3 12))  xlabel(-2(2)12, labsize(medsmall)) ytitle("Number of Primaries" "(Opposed Races)", size(medlarge)) xscale(titlegap(2.5))  ///
	graphregion(color(white)) legend(off)

******************************************************************************************
*FIGURE A3
*use "votesreceipts.dta", clear

histogram pripctreceipts, percent bin(10)  bcolor(gs13) ytitle("Percent of Observations", size(medlarge))  ///
	xscale(range(0 1)) xlabel(0(.2)1, labsize(medsmall)) xtitle("Primary Receipt Share", size(medlarge)) graphregion(color(white)) legend(off)  ///
	yscale(range(0 50)) ylabel(0(10)50, labsize(medsmall) angle(0)) yscale(titlegap(2)) xscale(titlegap(2)) title("All Candidates", size(vlarge) color(black))

histogram pripctreceipts if priuo==0, percent bin(10)  bcolor(gs13) ytitle("Percent of Observations", size(medlarge))  ///
	xscale(range(0 1)) xlabel(0(.2)1, labsize(medsmall)) xtitle("Primary Receipt Share", size(medlarge)) graphregion(color(white)) legend(off)  ///
	yscale(range(0 50)) ylabel(0(10)50, labsize(medsmall) angle(0)) yscale(titlegap(2)) xscale(titlegap(2)) title("Opposed Candidates", size(vlarge) color(black))

histogram pripctreceipts if incum==0, percent bin(10)  bcolor(gs13) ytitle("Percent of Observations", size(medlarge))  ///
	xscale(range(0 1)) xlabel(0(.2)1, labsize(medsmall)) xtitle("Primary Receipt Share", size(medlarge)) graphregion(color(white)) legend(off)  ///
	yscale(range(0 50)) ylabel(0(10)50, labsize(medsmall) angle(0)) yscale(titlegap(2)) xscale(titlegap(2)) title("Nonincumbents", size(vlarge) color(black))

******************************************************************************************
*FIGURE A5, FIGURE A6, TABLE A2, TABLE A3, TABLE A4, FIGURE A7
*use "votemoneydata_primary.dta", clear

*FIGURE A5
qui reg competitiveprivotes_575 i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr) 
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 .8)) ylabel(0(.2).8, labsize(medium) angle(0)) ytitle("Competitive Primary", size(large)) yscale(titlegap(2.5)) ///
	xtitle("") title("(a)  57.5% of Votes", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xscale(range(.75 3.2)) xlabel(1 "   Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.225 1.5  "Challenger", size(medlarge) place(n)) text(.075 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.6 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg competitiveprireceipts_575 i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr) 
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 .8)) ylabel(0(.2).8, labsize(medium) angle(0)) ytitle("Competitive Primary", size(large)) yscale(titlegap(2.5)) ///
	xtitle("") title("(b)  57.5% of Receipts", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xscale(range(.75 3.2)) xlabel(1 "   Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.11 1.5  "Challenger", size(medlarge) place(n)) text(.05 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.45 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg competitiveprivotes_toptwo20 i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr) 
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 .8)) ylabel(0(.2).8, labsize(medium) angle(0)) ytitle("Competitive Primary", size(large)) yscale(titlegap(2.5)) ///
	xtitle("") title("(c)  20-Pt Victory Margin", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xscale(range(.75 3.2)) xlabel(1 "   Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.21 1.5  "Challenger", size(medlarge) place(n)) text(.07 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.53 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg competitiveprireceipts_toptwo20 i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr) 
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 .8)) ylabel(0(.2).8, labsize(medium) angle(0)) ytitle("Competitive Primary", size(large)) yscale(titlegap(2.5)) ///
	xtitle("") title("(d)  20-Pt Fundraising Margin", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xscale(range(.75 3.2)) xlabel(1 "   Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.1 1.5  "Challenger", size(medlarge) place(n)) text(.05 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.39 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

*FIGURE A6
qui reg npricands i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr) 
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 5.1)) ylabel(0(1)5, labsize(medium) angle(0)) ytitle("Number of Candidates", size(large)) ///
	yscale(titlegap(2.5)) xtitle("") title("(a)  Total Number of Candidates" "(Ballot)", color(black) size(vlarge) bexpand nospan) ///
	xscale(range(.75 3.2)) xlabel(1 "   Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(1.05 1.5  "Challenger", size(medlarge) place(n)) text(1.1 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(4.05 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg effectivecands_votes i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr) 
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 5.1)) ylabel(0(1)5, labsize(medium) angle(0)) ytitle("Number of Candidates", size(large)) ///
	yscale(titlegap(2.5)) xtitle("") title("(b)  Effective Number of Candidates" "(Votes)", color(black) size(vlarge) bexpand nospan) ///
	xscale(range(.75 3.2)) xlabel(1 "   Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.85 1.5  "Challenger", size(medlarge) place(n)) text(.8 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(2.8 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg effectivecands i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr) 
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 5.1)) ylabel(0(1)5, labsize(medium) angle(0)) ytitle("Number of Candidates", size(large)) ///
	yscale(titlegap(2.5)) xtitle("") title("(c)  Effective Number of Candidates" "(Receipts)", color(black) size(vlarge) bexpand nospan) ///
	xscale(range(.75 3.2)) xlabel(1 "   Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.6 1.5  "Challenger", size(medlarge) place(n)) text(.65 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(2.4 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

*TABLE A2
qui ologit diff_votereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
eststo ta2_1
qui ologit diff_toptwovotereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
eststo ta2_2
qui reg diff_effective i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta2_3
qui reg diff_effectivevotes i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta2_4

esttab ta2_1 ta2_2 ta2_3 ta2_4, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) stats(N r2_p r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) 

*TABLE A3 
qui reg competitivepridisb_575 i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)  
eststo ta3_1
qui reg competitivepridisb_toptwo i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)  
eststo ta3_2
qui reg effectivecands_disb i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)  
eststo ta3_3

esttab ta3_1 ta3_2 ta3_3, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) stats(N r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) 

*TABLE A4
qui ologit diff_votedisb i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)   
eststo ta4_1
qui ologit diff_toptwovotedisb i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)   
eststo ta4_2
qui reg diff_effectivedisb i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta4_3
qui reg diff_effectivevotesdisb i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta4_4

esttab ta4_1 ta4_2 ta4_3 ta4_4, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) stats(N r2_p r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) 

*FIGURE A7
qui ologit diff_votedisb i.partybalance##i.seattype i.stcd i.year, cluster(stcdyr)   
margins, predict(outcome(1)) at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 .25)) ylabel(0(.05).25, labsize(medium) angle(0)) ytitle("P(Competitive)," "Votes Not Spending", size(large)) ///
	yscale(titlegap(2.5)) title("(a)  57.5% of Votes vs. Spending", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.75 3.2)) xlabel(1 "    Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.095 1.5  "Challenger", size(medlarge) place(n)) text(.038 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.18 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui ologit diff_toptwovotedisb i.partybalance##i.seattype  i.stcd i.year, cluster(stcdyr)   
margins, predict(outcome(1)) at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 .25)) ylabel(0(.05).25, labsize(medium) angle(0)) ytitle("P(Competitive)," "Votes Not Spending", size(large)) ///
	yscale(titlegap(2.5)) title("(b)  20-Pt Vote vs. Spending Margin", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.75 3.2)) xlabel(1 "    Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.093 1.5  "Challenger", size(medlarge) place(n)) text(.04 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.185 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg diff_effectivedisb i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr)  
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 2.5)) ylabel(0(.5)2.5, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Spending)", size(large)) ///
	yscale(titlegap(2.5)) title("(c)  Total vs. Effective (Spending)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.75 3.2)) xlabel(1 "    Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.2 1.5  "Challenger", size(medlarge) place(n)) text(.26 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(1.73 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg diff_effectivevotesdisb i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr)  
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 2.5)) ylabel(0(.5)2.5, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Spending)", size(large)) ///
	yscale(titlegap(2.5)) title("(d)  Effective (Votes vs. Spending)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.75 3.2)) xlabel(1 "    Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.03 1.5  "Challenger", size(medlarge) place(n)) text(-.02 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.5 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

******************************************************************************************
*TABLE A5, TABLE A6, TABLE A7
*use "votemoneydata_primary_excludeloans.dta", clear

*TABLE A5
qui reg competitiveprivotes_575 i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)
eststo ta5_1
qui reg competitiveprireceipts_575 i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)
eststo ta5_2
qui reg competitiveprivotes_toptwo i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)
eststo ta5_3
qui reg competitiveprireceipts_toptwo i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr) 
eststo ta5_4

esttab ta5_1 ta5_2 ta5_3 ta5_4, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) stats(N r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) 

*TABLE A6
qui reg npricands i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)
eststo ta6_1
qui reg effectivecands_votes i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta6_2
qui reg effectivecands i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta6_3

esttab ta6_1 ta6_2 ta6_3, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) stats(N r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) 

*TABLE A7
qui ologit diff_votereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
eststo ta7_1
qui ologit diff_toptwovotereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr) 
eststo ta7_2
qui reg diff_effective i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta7_3
qui reg diff_effectivevotes i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta7_4

esttab ta7_1 ta7_2 ta7_3 ta7_4, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) stats(N r2_p r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) 

******************************************************************************************
*TABLE A8, TABLE A9, TABLE A10
*use "votemoneydata_primary_nodropouts.dta", clear

*TABLE A8
qui reg competitiveprivotes_575 i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)
eststo ta8_1
qui reg competitiveprireceipts_575 i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)
eststo ta8_2
qui reg competitiveprivotes_toptwo20 i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)
eststo ta8_3
qui reg competitiveprireceipts_toptwo20 i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)
eststo ta8_4

esttab ta8_1 ta8_2 ta8_3 ta8_4, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) stats(N r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) 

*TABLE A9
qui reg npricands i.openseat##i.partybalance i.challengerparty i.year i.stcd, robust cluster(stcdyr)
eststo ta9_1
qui reg effectivecands_votes i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta9_2
qui reg effectivecands i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta9_3

esttab ta9_1 ta9_2 ta9_3, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) stats(N r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) 

*TABLE A10
qui ologit diff_votereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr) 
eststo ta10_1
qui ologit diff_toptwovotereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr) 
eststo ta10_2
qui reg diff_effective i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta10_3
qui reg diff_effectivevotes i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta10_4

esttab ta10_1 ta10_2 ta10_3 ta10_4, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) stats(N r2_p r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance cut1 cut2 _cons) 

******************************************************************************************
*TABLE A11, TABLE A12
*use "votemoneydata_primary.dta", clear

*TABLE A11
qui ologit diff_votereceipts i.openseat##i.partybalance i.challengerparty totalpartydistrictdonors10 i.stcd i.year, cluster(stcdyr)
eststo ta11_1
qui ologit diff_toptwovotereceipts i.openseat##i.partybalance i.challengerparty totalpartydistrictdonors10 i.stcd i.year, cluster(stcdyr)
eststo ta11_2
qui reg diff_effective i.openseat##i.partybalance i.challengerparty totalpartydistrictdonors10 i.stcd i.year, robust cluster(stcdyr) 
eststo ta11_3
qui reg diff_effectivevotes i.openseat##i.partybalance i.challengerparty totalpartydistrictdonors10 i.stcd i.year, robust cluster(stcdyr) 
eststo ta11_4

esttab ta11_1 ta11_2 ta11_3 ta11_4, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance totalpartydistrictdonors10 cut1 cut2 _cons) stats(N r2_p r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance totalpartydistrictdonors10 cut1 cut2 _cons) 

*TABLE A12
qui ologit diff_votereceipts i.openseat##i.partybalance i.challengerparty logprepri_coordpartyexpenditures logprepri_indexpenditures i.stcd i.year, cluster(stcdyr)
eststo ta12_1
qui ologit diff_toptwovotereceipts i.openseat##i.partybalance i.challengerparty logprepri_coordpartyexpenditures logprepri_indexpenditures i.stcd i.year, cluster(stcdyr)
eststo ta12_2
qui reg diff_effective i.openseat##i.partybalance i.challengerparty logprepri_coordpartyexpenditures logprepri_indexpenditures i.stcd i.year, robust cluster(stcdyr) 
eststo ta12_3
qui reg diff_effectivevotes i.openseat##i.partybalance i.challengerparty logprepri_coordpartyexpenditures logprepri_indexpenditures i.stcd i.year, robust cluster(stcdyr) 
eststo ta12_4

esttab ta12_1 ta12_2 ta12_3 ta12_4, keep(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance logprepri_coordpartyexpenditures logprepri_indexpenditures cut1 cut2 _cons) stats(N r2_p r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance logprepri_coordpartyexpenditures logprepri_indexpenditures cut1 cut2 _cons) 

******************************************************************************************
*FIGURE A8 
*use "votemoneydata_primary.dta", clear

qui ologit diff_PRVYEvotereceipts i.partybalance##i.seattype i.stcd i.year, cluster(stcdyr) 
margins, predict(outcome(1)) at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 .4)) ylabel(0(.1).4, labsize(medium) angle(0)) ytitle("P(Competitive)," "Votes Not Receipts", size(large)) ///
	yscale(titlegap(2.5)) title("(a)  57.5% of Votes vs. Receipts", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.8 3.2)) xlabel(1 "  Disadvantaged" 2 "Parties-Balanced" 3 "Advantaged   ", labsize(large)) ///
	text(.125 1.5  "Challenger", size(medlarge) place(n)) text(.068 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.33 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui ologit diff_PRVYEtoptwovotereceipts i.partybalance##i.seattype i.stcd i.year, cluster(stcdyr) 
margins, predict(outcome(1)) at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 .4)) ylabel(0(.1).4, labsize(medium) angle(0)) ytitle("P(Competitive)," "Votes Not Receipts", size(large)) ///
	yscale(titlegap(2.5)) title("(b)  20-Pt Vote vs. Receipt Margin", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.8 3.2)) xlabel(1 "  Disadvantaged" 2 "Parties-Balanced" 3 "Advantaged   ", labsize(large)) ///
	text(.115 1.5  "Challenger", size(medlarge) place(n)) text(.06 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.33 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg diff_PRVYEeffective i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr)
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 3.4)) ylabel(0(1)3, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Receipts)", size(large)) ///
	yscale(titlegap(2.5)) title("(c)  Total vs. Effective (Receipts)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.8 3.2)) xlabel(1 "  Disadvantaged" 2 "Parties-Balanced" 3 "Advantaged   ", labsize(large)) ///
	text(.8 1.5  "Challenger", size(medlarge) place(n)) text(.65 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(2.5 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)
	
qui reg diff_PRVYEeffectivevotes i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr)
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	yscale(range(0 3.4)) ylabel(0(1)3, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Receipts)", size(large)) ///
	yscale(titlegap(2.5)) title("(d)  Effective (Votes vs. Receipts)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	xtitle("") xscale(range(.8 3.2)) xlabel(1 "  Disadvantaged" 2 "Parties-Balanced" 3 "Advantaged   ", labsize(large)) ///
	text(.075 1.5  "Challenger", size(medlarge) place(n)) text(.3 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(1.14 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

******************************************************************************************
*FIGURE A9
*use "votemoneydata_primary.dta", clear

qui reg herfindex_votes i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr)
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	title("") yscale(range(0 1)) yscale(titlegap(2)) ylabel(0(.2)1, labsize(medium) angle(0)) ///
	ytitle("HHI (Votes)", size(large)) xtitle("") ///
	xscale(range(.75 3.2)) xlabel(1 "   Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.83 1.5  "Challenger", size(medlarge) place(n)) text(.9 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.44 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg herfindex_receipts i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr)
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	title("") yscale(range(0 1)) yscale(titlegap(2)) ylabel(0(.2)1, labsize(medium) angle(0)) ///
	ytitle("HHI (Receipts)", size(large)) xtitle("") ///
	xscale(range(.75 3.2)) xlabel(1 "   Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(.82 1.5  "Challenger", size(medlarge) place(n)) text(.87 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(.51 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

qui reg diff_herfindex i.partybalance##i.seattype i.stcd i.year, robust cluster(stcdyr)
margins, at(partybalance=(1(1)3) seattype=(1(1)3)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(gs7) mcolor(gs7) lwidth(med)) ///
	plot3opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(gs7)) ci3opts(color(black)) ///
	title("") yscale(range(-.4 0)) yscale(titlegap(-11)) ylabel(-.4(.1)0, labsize(medium) angle(0)) ///
	ytitle("Change in HHI" "(Votes — Receipts) / Votes", size(large)) ///
	xtitle("") xscale(range(.75 3.2)) xlabel(1 "    Disadvantaged" 2 "    Parties-Balanced" 3 "Advantaged  ", labsize(large)) ///
	text(-.19 1.5  "Challenger", size(medlarge) place(n)) text(-.12 2.5 "Incumbent", size(medlarge) place(n)) ///
	text(-.29 1.98 "Open-Seat", size(medlarge) place(n)) graphregion(color(white)) legend(off)

******************************************************************************************
*TABLE A13
*use "voteprice.dta", clear

qui reg voteprice i.under10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, robust cluster(stcdyr)
eststo ta13

esttab ta13, keep(1.under10pct 1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) stats(N r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.under10pct 1.openseat 1.challengerparty 2.partybalance 3.partybalance ///
	1.openseat#2.partybalance 1.openseat#3.partybalance _cons) 

******************************************************************************************
*FIGURE A10
*use "genvotesreceipts.dta", clear

*Label variables
lab var genpctvote "Percent General Election Vote"
lab var genpctreceipts "Percent General Election Receipts"

binsreg genpctvote genpctreceipts, dots(0,0) line(3,3) polyreg(3) bycolors(gs5) ///
	xtitle("General Election Receipt Share", size(medlarge)) graphregion(color(white)) legend(off) title("") ///
	ytitle("General Election Vote Share", size(medlarge)) yscale(range(0 1.01)) ylabel(0(.2)1, labsize(medsmall) angle(0)) yscale(titlegap(2)) xscale(titlegap(2)) 

******************************************************************************************
*TABLE A14, FIGURE A11
*use "votemoneydata_general.dta", clear

*TABLE A14
qui ologit diff_genvotereceipts i.openseat##i.competitivedistrict i.stcd i.year
eststo ta14_1
qui reg diff_geneffective i.openseat##i.competitivedistrict i.stcd i.year, robust 
eststo ta14_2
qui reg diff_geneffectivevotes i.openseat##i.competitivedistrict i.stcd i.year, robust 
eststo ta14_3

esttab ta14_1 ta14_2 ta14_3, keep(1.openseat 1.competitivedistrict ///
	1.openseat#1.competitivedistrict cut1 cut2 _cons) stats(N r2_p r2, fmt(%9.0fc %9.2fc)) ///
	label replace b(2) se(2) star(* 0.05 ** 0.01) ///
	order(1.openseat 1.competitivedistrict ///
	1.openseat#1.competitivedistrict cut1 cut2 _cons) 

*FIGURE A11
qui ologit diff_genvotereceipts i.openseat##i.competitivedistrict i.stcd i.year
margins, predict(outcome(1)) at(competitivedistrict=(0 1) openseat=(0 1)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(black)) ///
	yscale(range(0 .5)) ylabel(0(.1).5, labsize(medium) angle(0)) ytitle("P(Competitive)," "Votes Not Receipts", size(large)) ///
	xtitle("") xscale(range(-.3 1.3)) xlabel(0 `""Uncompetitive" "District""' 1 `""Competitive" "District""', labsize(large)) ///
	yscale(titlegap(2.5)) text(.275 .55  "Open-Seat", size(medlarge) place(n)) text(.09 .5 "Incumbent", size(medlarge) place(n)) ///
	title("(a)  57.5% of Votes vs. Receipts", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	graphregion(color(white)) legend(off)

qui reg diff_geneffective i.openseat##i.competitivedistrict i.stcd i.year, robust 
margins, at(competitivedistrict=(0 1) openseat=(0 1)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(black)) ///
	yscale(range(0 1)) ylabel(0(.2)1, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Receipts)", size(large)) ///
	xtitle("") xscale(range(-.3 1.3)) xlabel(0 `""Uncompetitive" "District""' 1 `""Competitive" "District""', labsize(large)) ///
	yscale(titlegap(2.5)) title("(b)  Total vs. Effective (Receipts)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	text(.58 .4  "Incumbent", size(medlarge) place(n)) text(.26 .5 "Open-Seat", size(medlarge) place(n)) ///
	graphregion(color(white)) legend(off)
	
qui reg diff_geneffectivevotes i.openseat##i.competitivedistrict i.stcd i.year, robust 
margins, at(competitivedistrict=(0 1) openseat=(0 1)) 
marginsplot, plot1opts(lcolor(gs12) mcolor(gs12) lwidth(med)) plot2opts(lcolor(black) mcolor(black) lwidth(med)) ///
	ci1opts(color(gs12)) ci2opts(color(black)) ///
	yscale(range(0 1)) ylabel(0(.2)1, labsize(medium) angle(0)) ytitle("Difference in Candidates" "(Votes — Receipts)", size(large)) ///
	xtitle("") xscale(range(-.3 1.3)) xlabel(0 `""Uncompetitive" "District""' 1 `""Competitive" "District""', labsize(large)) ///
	yscale(titlegap(2.5)) title("(c)  Effective (Votes vs. Receipts)", color(black) size(vlarge) margin(b=3) bexpand nospan) ///
	text(.393 .4  "Incumbent", size(medlarge) place(n)) text(.15 .5 "Open-Seat", size(medlarge) place(n)) ///
	graphregion(color(white)) legend(off)

******************************************************************************************
*FIGURE A12
*use "combinedprimarygeneral.dta", clear

graph twoway (line overallcomp_575votes year if competitivedistrict==1 & openseat==1, lcolor(gs9) lwidth(medthick)) || ///
	(line overallcomp_575votes year if competitivedistrict==1 & openseat==0, lcolor(gs9) lpattern(dash) lwidth(medthick)) || ///
	(line overallcomp_575votes year if competitivedistrict==0 & openseat==1, lcolor(black) lwidth(medthick)) || ///
	(line overallcomp_575votes year if competitivedistrict==0 & openseat==0, lcolor(black) lpattern(dash) lwidth(medthick)),  ///
	yscale(range(0 2)) yscale(titlegap(2.5)) ylabel(0(.5)2, labsize(medsmall) angle(0))  ytitle("Competitive Race (Votes)", size(medlarge))  ///
	xlabel(1980(4)2020, labsize(medsmall)) xtitle("") graphregion(color(white))  /// 
	xscale(range(1980 2021)) legend(order(1 "Competitive Open-Seat" 3 "Uncompetitive Open-Seat" 2 "Competitive Incumbent-Contested" ///
	4 "Uncompetitive Incumbent-Contested") ///
	region(lstyle(none) lcolor(white))) legend(size(small) symxsize(*.7))

graph twoway (line overallcomp_575receipts year if competitivedistrict==1 & openseat==1, lcolor(gs9) lwidth(medthick)) || ///
	(line overallcomp_575receipts year if competitivedistrict==1 & openseat==0, lcolor(gs9) lpattern(dash) lwidth(medthick)) || ///
	(line overallcomp_575receipts year if competitivedistrict==0 & openseat==1, lcolor(black) lwidth(medthick)) || ///
	(line overallcomp_575receipts year if competitivedistrict==0 & openseat==0, lcolor(black) lpattern(dash) lwidth(medthick)),  ///
	yscale(range(0 2)) yscale(titlegap(2.5)) ylabel(0(.5)2, labsize(medsmall) angle(0))  ytitle("Competitive Race (Receipts)", size(medlarge))  ///
	xlabel(1980(4)2020, labsize(medsmall)) xtitle("") graphregion(color(white))  /// 
	xscale(range(1980 2021)) legend(order(1 "Competitive Open-Seat" 3 "Uncompetitive Open-Seat" 2 "Competitive Incumbent-Contested" /// 
	4 "Uncompetitive Incumbent-Contested") ///
	region(lstyle(none) lcolor(white))) legend(size(small) symxsize(*.7))

graph twoway (line overallcands_total year if competitivedistrict==1 & openseat==1, lcolor(gs9) lwidth(medthick)) || ///
	(line overallcands_total year if competitivedistrict==1 & openseat==0, lcolor(gs9) lpattern(dash) lwidth(medthick)) || ///
	(line overallcands_total year if competitivedistrict==0 & openseat==1, lcolor(black) lwidth(medthick)) || ///
	(line overallcands_total year if competitivedistrict==0 & openseat==0, lcolor(black) lpattern(dash) lwidth(medthick)),  ///
	yscale(range(1 9)) yscale(titlegap(2.5)) ylabel(2(2)8, labsize(medsmall) angle(0))  ytitle("Total Candidates (Ballot)", size(medlarge))  ///
	xlabel(1980(4)2020, labsize(medsmall)) xtitle("") graphregion(color(white))  /// 
	xscale(range(1980 2021)) legend(order(1 "Competitive Open-Seat" 3 "Uncompetitive Open-Seat" 2 "Competitive Incumbent-Contested" ///
	4 "Uncompetitive Incumbent-Contested") ///
	region(lstyle(none) lcolor(white))) legend(size(small) symxsize(*.7))

graph twoway (line overallcands_effective year if competitivedistrict==1 & openseat==1, lcolor(gs9) lwidth(medthick)) || ///
	(line overallcands_effective year if competitivedistrict==1 & openseat==0, lcolor(gs9) lpattern(dash) lwidth(medthick)) || ///
	(line overallcands_effective year if competitivedistrict==0 & openseat==1, lcolor(black) lwidth(medthick)) || ///
	(line overallcands_effective year if competitivedistrict==0 & openseat==0, lcolor(black) lpattern(dash) lwidth(medthick)),  ///
	yscale(range(1 9)) yscale(titlegap(2.5)) ylabel(2(2)8, labsize(medsmall) angle(0))  ytitle("Effective Candidates (Receipts)", size(medlarge))  ///
	xlabel(1980(4)2020, labsize(medsmall)) xtitle("") graphregion(color(white))  /// 
	xscale(range(1980 2021)) legend(order(1 "Competitive Open-Seat" 3 "Uncompetitive Open-Seat" 2 "Competitive Incumbent-Contested" ///
	4 "Uncompetitive Incumbent-Contested") ///
	region(lstyle(none) lcolor(white))) legend(size(small) symxsize(*.7))

******************************************************************************************
*Descriptive Statistics in Paper
******************************************************************************************
*Measuring Electoral Competition section
*use "votemoneydata_primary_fullsample.dta", clear

*Difference between top two vote getters and top two fundraisers, at primary level
sum toptwomargin_votes if priuo==0
sum toptwomargin_receipts if priuo==0
sum toptwomargin_votes 
sum toptwomargin_receipts 
sum toptwomargin_votes if openseat==1 & partybalance==3 & priuo==0
sum toptwomargin_receipts if openseat==1 & partybalance==3 & priuo==0

*Long-shot candidates (total and share)
sum totalunder10pct if partybalance==3 & openseat==1 
sum totalunder10pct if (partybalance!=3 | openseat!=1)
sum sharelongshot if partybalance==3 & openseat==1 
sum sharelongshot if (partybalance!=3 | openseat!=1) 

*Difference between top two vote getters where top vote getter won with less than 57.5 of vote
sum toptwomargin_votes if competitiveprivotes_575==1 
count if competitiveprivotes_575==1 & toptwomargin_votes>.2
count if competitiveprivotes_575==1 
sum toptwomargin_votes if competitiveprivotes_575==1 & openseat==1 & partybalance==3 & priuo==0

*********************************************
*Descriptive Trends Over Time section
*use "votemoneydata_primary.dta", clear

*Average percentage of competitive races
sum competitiveprivotes_575 competitiveprireceipts_575 if openseat==1
sum competitiveprivotes_575 competitiveprireceipts_575 if challengerparty==1 
sum competitiveprivotes_575 competitiveprireceipts_575 if incumcontested==1

*Total number of competitive primaries with each measure
tab competitiveprivotes_575  if incumcontested==1
tab competitiveprireceipts_575 if incumcontested==1
tab competitiveprivotes_575 if challengerparty==1
tab competitiveprireceipts_575 if challengerparty==1
tab competitiveprivotes_575 if openseat==1
tab competitiveprireceipts_575 if openseat==1

tab competitiveprivotes_575 
tab competitiveprireceipts_575

*Average number of candidates
sum npricands effectivecands if incumcontested==1
sum npricands effectivecands if challengerparty==1 
sum npricands effectivecands if openseat==1
corr npricands effectivecands effectivecands_votes

sum npricands if incumcontested==1 & year<2008
sum npricands if challengerparty==1 & year<2008
sum npricands if openseat==1 & year<2008
sum npricands if incumcontested==1 & year>2006
sum npricands if challengerparty==1 & year>2006
sum npricands if openseat==1 & year>2006

*2008 vs. 2020
sum npricands if year==2008 & openseat==1 
sum npricands if year==2020 & openseat==1 
sum effectivecands if year==2008 & openseat==1 
sum effectivecands if year==2020 & openseat==1 

sum npricands if year==2008 & incumcontested==1 
sum npricands if year==2020 & incumcontested==1 
sum effectivecands if year==2008 & incumcontested==1 
sum effectivecands if year==2020 & incumcontested==1 

*********************************************
*Results section

*Difference in competitive race, predicted values
qui ologit diff_votereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, predict(outcome(1)) at(openseat=1 challengerparty=0 partybalance=3) 
qui ologit diff_toptwovotereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, predict(outcome(1)) at(openseat=1 challengerparty=0 partybalance=3) 
qui ologit diff_votereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, predict(outcome(1)) at(openseat=1 challengerparty=0 partybalance=2) 
qui ologit diff_toptwovotereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, predict(outcome(1)) at(openseat=1 challengerparty=0 partybalance=2) 

*Opposed races 
qui ologit diff_votereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year if priuo==0, cluster(stcdyr)
margins, predict(outcome(1)) at(openseat=1 challengerparty=0 partybalance=2) 
qui ologit diff_toptwovotereceipts i.openseat##i.partybalance i.challengerparty i.stcd i.year if priuo==0, cluster(stcdyr)
margins, predict(outcome(1)) at(openseat=1 challengerparty=0 partybalance=2) 

*Number of competitive primaries in safe or competitive open seats 
tab competitiveprivotes_575 if openseat==1 & partybalance==3
tab competitiveprireceipts_575 if openseat==1 & partybalance==3
tab competitiveprivotes_575 if openseat==1 & partybalance==2
tab competitiveprireceipts_575 if openseat==1 & partybalance==2

*Difference in number of candidates, predicted values
qui reg diff_effective i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, at(openseat=1 challengerparty=0 partybalance=3) 
qui reg diff_effective i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, at(openseat=1 challengerparty=0 partybalance=2) 
qui reg diff_effectivevotes i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, at(openseat=1 challengerparty=0 partybalance=2) 

*Number of candidates, predicted values
qui reg npricands i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, at(openseat=1 challengerparty=0 partybalance=(3 2))
qui reg effectivecands i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, at(openseat=1 challengerparty=0 partybalance=(3 2))

*Effective number of candidates with votes and receipts in open seats
sum effectivecands_votes if openseat==1
sum effectivecands if openseat==1

*Difference in top two vote margin with more/fewer effective candidates
sum effectivecands if partybalance==3 & openseat==1
sum toptwomargin_votes if partybalance==3 & openseat==1 & effectivecands<2.6 
sum toptwomargin_votes if partybalance==3 & openseat==1 & effectivecands>2.6 

sum effectivecands if incumcontested==1 & priuo==0
sum toptwomargin_votes if incumcontested==1 & effectivecands<1.3 & priuo==0
sum toptwomargin_votes if incumcontested==1 & effectivecands>1.3 & priuo==0

*********************************************
*Long Shots section

*Number of long-shot candidates in safe open seats
sum totalunder10pct if openseat==1 & partybalance==3

*Difference in competitive race, predicted values
replace totalunder10pct=5 if totalunder10pct>5 & totalunder10pct!=.

qui ologit diff_votereceipts i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr) 
margins, predict(outcome(1)) at(openseat=1 challengerparty=0 partybalance=3 totalunder10pct=(3 4 5)) 
qui ologit diff_toptwovotereceipts i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr) 
margins, predict(outcome(1)) at(openseat=1 challengerparty=0 partybalance=3 totalunder10pct=(3 4 5)) 
qui reg diff_effective i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, at(openseat=1 challengerparty=0 partybalance=3 totalunder10pct=(1 2 3 4 5)) 
qui reg diff_effectivevotes i.totalunder10pct i.openseat##i.partybalance i.challengerparty i.stcd i.year, cluster(stcdyr)
margins, at(openseat=1 challengerparty=0 partybalance=3 totalunder10pct=(4 5)) 

*Vote price
*use "voteprice.dta", clear

sum voteprice if openseat==1, d
sum voteprice if openseat==1 & partybalance==3, d
sum voteprice if openseat==1 & under10pct==0, d
sum voteprice if openseat==1 & under10pct==1, d
sum voteprice if openseat==1 & partybalance==3 & under10pct==0, d
sum voteprice if openseat==1 & partybalance==3 & under10pct==1, d

*********************************************
*General Elections section
*use "votemoneydata_general.dta", clear

qui ologit diff_genvotereceipts i.openseat##i.competitivedistrict i.stcd i.year
margins, predict(outcome(1)) at(competitivedistrict=1 openseat=1) 
qui reg diff_geneffective i.openseat##i.competitivedistrict i.stcd i.year, robust 
margins, at(competitivedistrict=1 openseat=1) 

tab competitivegen_votes if competitivedistrict==1 & openseat==1
tab competitivegen_receipts if competitivedistrict==1 & openseat==1

*********************************************
*Appendix
*use "votemoneydata_primary.dta", clear

*Matches and unopposed
count if competitiveprivotes_575==competitiveprireceipts_575
tab priuo if competitiveprivotes_575==competitiveprireceipts_575

*Top two vote margin for mismatches 
sum toptwomargin_receipts if competitiveprireceipts_575==0 & competitiveprivotes_575==1 
sum toptwomargin_votes if competitiveprireceipts_575==0 & competitiveprivotes_575==1 
sum toptwomargin_receipts if competitiveprireceipts_575==0 & competitiveprivotes_575==1 & competitiveprivotes_toptwo20==0
sum toptwomargin_votes if competitiveprireceipts_575==0 & competitiveprivotes_575==1 & competitiveprivotes_toptwo20==0
sum totalunder10pct if competitiveprireceipts_575==0 & competitiveprivotes_575==1 & competitiveprivotes_toptwo20==0

tab incumcontested if competitiveprireceipts_575==0 & competitiveprivotes_575==1
tab blanket if competitiveprireceipts_575==0 & competitiveprivotes_575==1 & incumcontested==1
sum totalunder10pct if competitiveprireceipts_575==0 & competitiveprivotes_575==1 & incumcontested==1 & blanket==1

*Top two vote margin for mismatches, victory rates, long-shot candidates, open seats
tab openseat 
tab openseat if competitiveprireceipts_575==0 & competitiveprivotes_575==1

sum toptwomargin_receipts if competitiveprireceipts_575==0 & competitiveprivotes_575==1 & openseat==1
sum toptwomargin_votes if competitiveprireceipts_575==0 & competitiveprivotes_575==1 & openseat==1
count if competitiveprireceipts_575==0 & competitiveprivotes_575==1 & openseat==1 & toptwomargin_votes>.2
sum totalunder10pct if competitiveprireceipts_575==0 & competitiveprivotes_575==1 & openseat==1

*Combined primary and general election
*use "votemoneydata_general.dta", clear

tab openseat competitivedistrict if year==2020
tab openseat competitivedistrict if year==1980

******************************************************************************************
*END
